<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>

	<body style="padding: 0px;">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<div>
			<div style="float: right;margin-top: 0px;max-width:60px;" id="notreview"></div>
			<form id="ff" method="post">
				<div style="margin-left: 15%;padding: 30px 0px;">
					<table cellpadding="5" style="width: 85%;">
						<tr>
							<td width="10%" style="display: none;">合同ID</td>
							<td width="23%" style="display: none;">
								<input style="width:100%" class="easyui-textbox" type="text" id="input_TENANT_ID" name="TENANT_ID" data-options="required:true,prompt:'由系统自动生成，不需填写',disabled:true"></input>
							</td>
							<td width="10%">合同编号</td>
							<td width="23%">
								<input style="width:100%" class="easyui-textbox" id="input_ORDER_NO" name="ORDER_NO" data-options="required:true,prompt:'由系统自动生成，不需填写',disabled:true"></input>
							</td>
							<td width="10%">客户名称</td>
							<td width="23%">
								<input style="width:100%" class="easyui-textbox" type="text" id="input_TENANT_NAME" name="TENANT_NAME" data-options="required:true,disabled:true"></input>
							</td>
							<td width="10%">合同类型</td>
							<td width="23%">
								<input style="width:100%" class="easyui-combobox" type="text" id="input_CONTRACT_TYPE" name="CONTRACT_TYPE" data-options="required:true"></input>
							</td>
							<td>
								<input type="hidden" id="input_ID" NAME="ID" />
							</td>
						</tr>
						<tr>
							<!--<td width="10%">合同期限</td>
							<td width="23%">
								<input style="width:100%" class="easyui-textbox" type="contract_term" id="input_DEADLINE" name="DEADLINE" data-options="required:true"></input>
							</td>-->
							<td width="10%">开始时间</td>
							<td width="23%">
								<input style="width:100%" class="easyui-datebox" required data-options="validType:'md[\'10/11/2015\']',disabled:true" id="input_BEGIN_TIME" name="BEGIN_TIME"></input>
							</td>
							<td width="10%">结束时间</td>
							<td width="23%">
								<input style="width:100%" class="easyui-datebox" required data-options="validType:'md[\'10/11/2015\']',disabled:true" id="input_END_TIME" name="END_TIME"></input>
							</td>
							<td width="10%">总经营面积</td>
							<td width="23%">
								<input style="width:100%" class="easyui-numberbox" data-options="required:true,disabled:true" id="input_BUSINESS_AREA" name="BUSINESS_AREA" suffix=" m&sup2"></input>
							</td>
						</tr>
						<tr>
							<td width="10%">租金总额</td>
							<td width="23%">
								<input style="width:100%" class="easyui-numberbox" id="input_RENT_SUM" name="RENT_SUM" data-options="required:true,disabled:true" prefix="￥"></input>
							</td>
							<td width="10%">保证金总额</td>
							<td width="23%">
								<input style="width:100%" class="easyui-numberbox" type="text" id="input_MARGIN_SUM" name="MARGIN_SUM" data-options="required:true,disabled:true" prefix="￥"></input>
							</td>
							<td width="10%">其他费用合计</td>
							<td width="23%">
								<input style="width:100%" class="easyui-numberbox" type="text" id="input_OTHERS_SUM" name="OTHERS_SUM" data-options="required:true,disabled:true" prefix="￥"></input>
							</td>
						</tr>
					</table>
				</div>
				<div class="easyui-tabs" id="div_tabs" style="width: 100%">
					<div title="长期合同明细" style="overflow:hidden">
						<!--<iframe src="BIContractChangeList.html" style="width: 100%;height: 350px;" frameborder="0" scrolling="no"></iframe>-->
						<table id="tt">

						</table>
					</div>
					<div title="长期合同费用明细" style="overflow:hidden">
						<!--<iframe src="../BIContractCreate/BIContractAddCharge.html" style="width: 100%;height: 350px;" frameborder="0" scrolling="no"></iframe>-->
						<table id="tt1">

						</table>
					</div>
					<div title="卡证及责任书信息" style="overflow: hidden;">
						<table id="tt2">

						</table>
					</div>
				</div>

				<div style="padding: 10px 0px;">
					<table>
						<tr>
							<th>人民币金额合计</th>
							<td>
								<input type="text" style="border: none;" name="number" />
							</td>
							<th>人民币金额合计(大写)</th>
							<td width="auto">
								<input type="text" style="border: none;" id="dx" />
							</td>
						</tr>
					</table>
				</div>
				<div id="new_footer" style="margin-left: 23%;"></div>
			</form>
		</div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 100%;height: 100%;" frameborder="0" scrolling="no"></iframe>
		</div>
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/finance.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.edatagrid.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/MarketShareFunction/contractShareFunction.js"></script>
	</body>
	<script type="text/javascript">
		var currid = AddFlag; //当前页面的ID
		var id = getID(); //获取上个页面传回的ID
		var pageData;
		var currPage = 0; //当前的页数
		var cardDetail = new Array(); //用来存储卡证的信息
		var index = 0; //用来标志cardDetail数组的下标
		var MaxPage = 0;
		var MinPage = 1;
		var isVerify; //判断该合同是否审核
		var isExpire; //判断该合同是否停止
		var currRow;
		var typeInfo = new Array(); //将typeInfo初始化为数组
		var _detailToolbarData; //长期合同明细工具栏
		var _detailChargeToolbarData; //长期合同收费工具栏
		var _detailDutyAndCardToolbarData; //长期合同卡证以及责任书工具栏
		_detailToolbarData = AddDetailToolBar(482);
		_detailChargeToolbarData = AddDetailToolBar(258);
		_detailDutyAndCardToolbarData = AddDetailToolBar(258);
		Tabs_Hover();
		$(document).ready(function(){
		if(id != AddFlag && id != undefined) {
			currid = id;
			loadRemote();
		}
		});
		if(id == undefined) {
			currid = AddFlag;
		}
		///增加脚注
		getPageMaxAndMin();
		addFooter($("#new_footer"));
		//增加单据的toolba

		var extraTootbar = [{
			"icon": "icon-stopBoost",
			"func": "stopContract()",
			"functionname": "合同停止"
		}];

		//		var receipts_types = RECEIPT_CHARGE_SYMBOL;
		var receipts_type = RECEIPT_FRONT_SYMBOL;
		receipts_type += RECEIPT_NEXT_SYMBOL;
		receipts_type += RECEIPT_ADD_SYMBOL;
		receipts_type += RECEIPT_SAVE_SYMBOL;
		receipts_type += RECEIPT_DELETE_SYMBOL;
		receipts_type += RECEIPT_VERIFY_SYMBOL;
		receipts_type += RECEIPT_UNVERIFY_SYMBOL;
		receipts_type += RECEIPT_SEARCH_SYMBOL;
		receipts_type += RECEIPT_EXPORT_SYMBOL;
		receipts_type += RECEIPT_PRINT_SYMBOL;
		content = AddReceiptsToolBar(receipts_type, extraTootbar);
		$("#toolbar").append(content); /*在ID=toolbar的标记后面添加content中的内容*/

		function getPageMaxAndMin() {
			var _url = RemoteLinkAddress + "/market/contract/getmaxminid.do";
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: _url,
				dataType: "json", //服务器返回的数据类型
				success: function(result) {
					if(result != null) {
						console.log(result);
						MaxPage = result.MAXID;
						MinPage = result.MINID;
						currPage = result.MINID + 1;
					}
				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		//导出
		function exportExcel() {
			if(currid === AddFlag) {
				$.messager.alert("警告", "该订单为新增订单，无法导出Excel！");
				return;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						data: {
							"ID": currid
						},
						url: RemoteLinkAddress + "/market/contract/excelorder.do",
						dataType: "json", //服务器返回的数据类型
						success: function(result) {
							window.location.href = result.path;
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}

		function deletedata() {
			if(isVerify == 1) {
				$.messager.alert("警告", "订单已审核，无法删除");
				return;
			}
			if(isExpire === true) {
				$.messager.alert("警告", "该合同已经停止，无法进行删除操作");
				return;
			}
			$.messager.confirm("确认", "是否删除", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/contract/delete.do", {
						ID: currid
					}, function(result) {
						if(result.msg == "success") {
							frontpage();
							$.messager.alert({
								title: '成功',
								msg: '删除成功!'
							});
						} else {
							$.messager.alert({
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		function verifydata() {
			if(isExpire === true) {
				$.messager.alert("警告", "该合同已经停止，无法进行审核操作");
				return;
			}
			if(isVerify == 1) {
				$.messager.alert("警告", "订单已审核，无须再审");
				return;
			}
			$.messager.confirm("确认", "是否审核", function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/contract/verify.do", {
						"ID": currid,
					}, function(result) {
						if(result.msg == "success") {
							$.messager.alert({
								title: '成功',
								msg: '审核成功!'
							});
							verifyStatus(1, true);
							isVerify = 1;
						} else {
							$.messager.alert({
								title: 'Error',
								msg: result.msg
							});
						}
					}, 'json');
				}
			});
		}

		function unverifydata() {
			if(isExpire === true) {
				$.messager.alert("警告", "该合同已经停止，无法进行弃审操作");
				return;
			}
			if(isVerify == 0) {
				$.messager.alert("警告", "订单已弃审，无须再审");
				return;
			}
			$.messager.confirm('Confirm', '是否弃审', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/contract/unverify.do", {
							"ID": currid,
						},
						function(result) {
							if(result.msg == "success") {
								$.messager.alert({
									title: '成功',
									msg: '放弃审核成功!'
								});
								verifyStatus(0, true);
								isVerify = 0;
							} else {
								$.messager.alert({
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function print() {
			var pLocation = "";
			if(currid == AddFlag) {
				$.messager.alert("错误", "当前页面为新增页面不能打印");
				return;
			} else {
				pLocation = "BIContractLongPrint.html?id=" + currid;
				window.open(pLocation);
			}
		}

		function newdata() {
			currid = AddFlag;
			currPage = 0;
			$('#ff').form('reset');
			GetTable();
		}

		function frontpage() {
			if(currPage > MinPage) {
				var _url = RemoteLinkAddress + '/market/contract/pre.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert("提示", "没有上张");
			}
		}

		function nextpage() {
			if(currPage < MaxPage) {
				var _url = RemoteLinkAddress + '/market/contract/next.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert(" 提示", "没有下张");
			}

		}

		function searchmore() {
			AddTabIn("合同查询", parent.$('#tabs'), "UI/Market/BIContract/BIContractSearch.html");
		}

		function getRemoteData(_url) //统一获取远程的数据
		{
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: _url,
				dataType: "json", //服务器返回的数据类型
				success: function(result) {
					console.log(result);
					if(result != null) {
						getFormData(result);
						currid = result.ID;
						currPage = result.ID;
						isVerify = result.ISVERIFY;
						verifyStatus(isVerify, true);
						pageData = result;
						var longTermDetailData = result.rowsBoost;
						var longTermCharge = result.rowsCharge;
						addIdentifierForChargeData(longTermCharge);
						localStorage.setItem("longTermCharge", JSON.stringify(longTermCharge));
						$('#tt').datagrid('loadData', longTermDetailData);
						$('#tt1').datagrid('loadData', longTermCharge);
						$("#tt2").datagrid('loadData', longTermDetailData);
						loadCardAndDuty(result);
						if(result.STATE === "到期") {
							isExpire = true;
						}
					}

				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}
		//////////
		function loadRemote() { //载入服务器上的数据，用于修改以及查看更多的时候调用，根据id是否等于-1来判断
			var _url = RemoteLinkAddress + '/market/contract/findbyid.do?ID=' + currid;
			getRemoteData(_url);
		}

		GetTable();

		$('#input_sum').textbox({
			onChange: function(value) {
				var _trim = $.trim(value);
				var s = changeMoneyToChinese(_trim);
				$('#span_sum').html(s);
			}
		});

		function GetTable() {
			$('#tt').edatagrid({
				height: 280,
				toolbar: _detailToolbarData,
				singleSelect: 'true', //是否单选：是
				rownumbers: 'true',
				fitColumns: 'true', //自动调整列：是
				//				showFooter: 'true',
				autoSave: 'true',
				columns: [
					[{
						field: 'ID',
						title: 'ID',
						width: '0%',
						align: 'center',
					}, {
						field: 'BOOST_ID',
						title: '摊位ID',
						width: '0%',
						align: 'center',
						editor: {
							type: 'textbox',
							options: {
								valueField: "BOOST_ID",
								textField: "BOOST_ID",
								editable: false,
							}
						}
					}, {
						field: 'REGION_TYPE',
						title: '区域类型',
						width: '8%',
						align: 'center'
					}, {
						field: 'REGION_NAME',
						title: '区域名称',
						width: '7%',
						align: 'center'
					}, {
						field: 'HOUSE_NUMBER',
						title: '摊位门牌号',
						width: '8%',
						align: 'center'
					}, {
						field: 'BUSINESS_AREA',
						title: '经营面积',
						width: '8%',
						align: 'center',
						formatter: function(value, row, index) {
							if(value) {
								return value + " m&sup2";
							}
						}
					}, {
						field: 'RENT',
						title: '租金',
						width: '7%',
						align: 'center',
						editor: {
							type: 'numberbox',
							options: {
								required: true
							}
						},
						formatter: function(value, row, index) {
							if(value) {
								return "￥" + value;
							}
						}
					}, {
						field: 'MARGIN',
						title: '保证金',
						width: '7%',
						align: 'center',
						editor: {
							type: 'numberbox',
							options: {
								required: true
							}
						},
						formatter: function(value, row, index) {
							if(value) {
								return "￥" + value;
							}
						}
					}, {
						field: 'OTHERS_CHARGE',
						title: '其他费用',
						width: '7%',
						align: 'center',
						editor: {
							type: 'numberbox',
							options: {
								required: true
							}
						},
						formatter: function(value, row, index) {
							if(value) {
								return "￥" + value;
							}
						}
					}, {
						field: 'BEGIN_TIME',
						title: '合同开始时间',
						width: '7%',
						align: 'center'
					}, {
						field: 'END_TIME',
						title: '合同结束时间',
						width: '7%',
						align: 'center'
					}, {
						field: 'RENT_END',
						title: '实际租用结束时间',
						width: '7%',
						align: 'center',
						editor: {
							type: 'datebox',
							options: {
								required: true,
								editable: false,
								disabled: true
							}
						}
					}, {
						field: 'SUM',
						title: '小计',
						width: '7%',
						align: 'center',
						editor: {
							type: 'numberbox',
							options: {
								required: false,
								editable: false,
							}
						},
						formatter: function(value, row, index) {
							if(value) {
								return "￥" + value;
							}
						}
					}, {
						field: 'STATE',
						title: '摊位状态',
						width: '6%',
						align: 'center'
					}, {
						field: 'CHARGE',
						title: '摊位收费',
						width: '6%',
						align: 'center',
						formatter: function(value, row, index) {
							console.log(row.BOOST_ID);
							return '<a href="#" onclick="charge(' + row.BOOST_ID + ')">收费</a>';
						}
					}]
				],
				onDblClickRow: function(index, row) {
					currRow = row;
				},
				onAdd: function(index, row) {
					currRow = row;
				},
				onEndEdit: function(index, row, changes) {
					var sum = parseFloat(row.RENT) + parseFloat(row.MARGIN) + parseFloat(row.OTHERS_CHARGE);
					$('#tt').edatagrid('updateRow', {
						index: index,
						row: {
							SUM: sum
						}
					});
					$('#tt').edatagrid('refreshRow', index);
					autoCalculate();
				}
			});

			$('#tt1').edatagrid({
				height: 280,
				toolbar: _detailChargeToolbarData,
				pagination: 'true',
				rownumbers: 'true',
				singleSelect: true,
				fitColumns: true,
				autoSave: true,
				columns: [
					[{
						field: 'ID',
						title: 'ID',
						width: '0%',
						align: 'center',
					}, {
						field: 'CHARGENAME',
						title: '费用名称',
						width: '24%',
						align: 'center'
					}, {
						field: 'CHARGETYPE',
						title: '费用类型',
						width: '24%',
						align: 'center'
					}, {
						field: 'EVIDENCE_ID',
						title: '交易凭证号',
						width: '24%',
						align: 'center'
					}, {
						field: 'SUM',
						title: '金额',
						width: '23%',
						align: 'center',
						formatter: function(value, row, index) {
							if(value) {
								return "￥" + value;
							}
						}
					}]
				]
				//				onEndEdit: function(index, row, changes) { //在编辑完成或，执行该函数
				//					CalSum();
				//				}
			});

			$('#tt2').edatagrid({
				method: 'get',
				toolbar: _detailDutyAndCardToolbarData,
				pagination: 'true',
				rownumbers: 'true',
				fitColumns: 'false',
				singleSelect: 'true',
				autoSave: true,
				height: 280,
				columns: [
					[{
						field: 'BOOST_ID',
						title: 'BOOST_ID',
						width: '0%'
					}, {
						field: 'HOUSE_NUMBER',
						title: '摊位门牌号',
						width: '24%',
						align: 'center'
					}, {
						field: 'BUSINESS_AREA',
						title: '经营面积',
						width: '24%',
						align: 'center'
					}, {
						field: 'NAME',
						title: '责任书',
						width: '24%',
						align: 'center',
						editor: {
							type: 'combobox',
							options: {
								url: RemoteLinkAddress + "/market/duty/listall.do",
								valueField: "NAME",
								textField: "NAME",
								multiple: true,
								editable: true,
								required: true,
							}
						}
					}, {
						field: 'CARDNAME',
						title: '卡证',
						width: '24%',
						align: 'center',
						editor: {
							type: 'combobox',
							options: {
//								url: RemoteLinkAddress + "/market/boostcard/listall.do?",
								valueField: "NAME",
								textField: "NAME",
								multiple: true,
								editable: true,
								required: false,
								onSelect: function(record) {
									//									console.log(record);
									cardDetail[index] = record;
									index++;
									console.log(cardDetail);
								},
								onUnselect: function(record) {
									for(var i = 0; i < cardDetail.length; i++) {
										if(typeof(cardDetail[i]) != "undefined") {
											if(typeof(cardDetail[i].ID) != "undefined") {
												if(record.ID == cardDetail[i].ID) {
													cardDetail.splice(i, 1);
												}
											}
										}
									}
									console.log(cardDetail);
								}
							}
						}
					}]
				],
				onDblClickRow: function(index, row) {
					console.log(row.BOOST_ID);
					var rowIndex = $("#tt2").datagrid('getRowIndex', row);
					var target = $('#tt2').datagrid('getEditor', {
						'index': rowIndex,
						'field': 'CARDNAME'
					}).target;
					target.combobox('clear');
					var url = RemoteLinkAddress + "/market/boostcard/listall.do?BOOST_ID=" + row.BOOST_ID;
					target.combobox('reload', url);
				},
			});
			$('#tt2').datagrid('hideColumn', 'BOOST_ID'); //隐藏第一列

			$("#tt1").datagrid('hideColumn', 'ID');
			$("#tt").datagrid('hideColumn', 'ID');
			$("#tt").datagrid('hideColumn', 'BOOST_ID');
		}

		function save() {
			if(isVerify == 1){
				$.messager.alert("警告","该合同已审核，无法修改！");
				return;
			}
			getData();
		}

		function getData() {
			var data = Object();
			data = submitFormData();
			data.ID = currid;
			data.rowsBoost = new Array();
			data.rowsCharge = new Array();
			data.rowsDuty = new Array();
			data.rowsCard = new Array();
			var boostData = $("#tt").datagrid("getRows"); //得到长期合同明细数据
			var chargeData = $("#tt1").datagrid("getRows"); //得到收费明细数据
			var chargeAndDutyData = $("#tt2").datagrid("getRows"); //得到卡证与责任书的明细数据
			data.rowsBoost = boostData;
			data.rowsCharge = chargeData;
			data = rebuildCardAndDutyData(chargeAndDutyData, data, cardDetail);
			var totalCharge = getTotalCharge(data);
			data.SUM = totalCharge;
			localStorage.longTermContractData = JSON.stringify(data);
			submitData(data);
		}

		function submitData(_data) {
			var _senddata = JSON.stringify(_data);
			$.ajax({
				dataType: 'JSON',
				url: RemoteLinkAddress + "/market/contract/update.do",
				data: 'a=' + _senddata,
				type: "POST",
				success: function(result) {
					if(result.msg.search("success") > -1) {
						$.messager.alert("提示信息", "保存成功");
					} else {
						$.messager.alert("错误信息", "保存失败");
					}
				},
				error: function(result) {
					$.messager.alert("错误信息", "保存失败");
				}
			});
		}

		var dialogWidth = 400;
		var dialogHeight = 300;
		var AddDialog;

		function AddDict() {
			var pLocation = "UI/COMMON/DictData.html?id=-1";
			$("#ifrmEdit").attr("src", pLocation);
			constructDialog($("#dlg"), "添加基础信息", dialogWidth, dialogHeight);
			AddDialog.dialog('open');
		}

		function charge(id) {
			var pLocation = "UI/Market/BIContractCreate/BIContractAddCharge.html?id=" + id + "&ORDER_TYPE=1";
			$("#ifrmEdit").attr("src", pLocation);
			constructDialog($("#dlg"), "长期合同收费修改", 1100, 410);
			AddDialog.dialog('open');
		}

		function checkDataIntegrity() {
			var customername = $("input[name='CUSTOMER_NAME']").val();
			var begintime = $("input[name='BEGIN_TIME']").val();
			var endtime = $("input[name='END_TIME']").val();
			var businessarea = $("input[name='BUSINESS_AREA']").val();
			var rentsum = $("input[name='RENT_SUM']").val();
			var marginsum = $("input[name='MARGIN_SUM']").val();
			var otherssum = $("input[name='OTHERS_SUM']").val();
			var rowsdata = $("#tt").datagrid('getRows');
			console.log(rowsdata);
			if(customername != "" && begintime != "" && endtime != "" && businessarea != "" && rentsum != "" && marginsum != "" && otherssum != "") {
				if(rowsdata.length != 0) {
					for(var i = 0; i < rowsdata.length; i++) {
						var region = rowsdata[i].REGION;
						var regiontype = rowsdata[i].REGION_TYPE;
						var housenumber = rowsdata[i].HOUSE_NUMBER;
						var businessarea = rowsdata[i].BUSINESS_AREA;
						var rent = rowsdata[i].RENT;
						var unitrent = rowsdata[i].UNIT_RENT;
						var unitlen = rowsdata[i].UNIT_LEN;
						var unit = rowsdata[i].UNIT;
						var margin = rowsdata[i].MARGIN;
						var othercharge = rowsdata[i].OTHERS_CHARGE;
						var begintime = rowsdata[i].BEGIN_TIME;
						var endtime = rowsdata[i].END_TIME;
						var rentend = rowsdata[i].RENT_END;
						if(region == "" || regiontype == "" || housenumber == "" || businessarea == "" || rent == "" || unitrent == "" || unitlen == "" || unit == "" || margin == "" || othercharge == "" || begintime == "" || endtime == "" || rentend == "") {
							return 0;
						}
					}
				} else {
					return 0;
				}
			} else {
				return 0;
			}
		}

		function loadCardAndDuty(totalData) {
			var tt2Data = $("#tt2").datagrid('getRows');
			console.log(tt2Data.length);
			for(var i = 0; i < tt2Data.length; i++) {
				var countCardName = 0; //卡证计数器
				var countDuty = 0; //责任书计数器
				for(var j = 0; j < totalData.rowsCard.length; j++) {
					if(tt2Data[i].BOOST_ID === totalData.rowsCard[j].BOOST_ID) {
						if(countCardName === 0) { //只有一个卡证的情况
							tt2Data[i].CARDNAME = totalData.rowsCard[j].CARDNAME;
							countCardName++;
						} else {
							tt2Data[i].CARDNAME += "," + totalData.rowsCard[j].CARDNAME;
							countCardName++;
						}
					}
				}
				for(var j = 0; j < totalData.rowsDuty.length; j++) {
					if(tt2Data[i].BOOST_ID === totalData.rowsDuty[j].BOOST_ID) {
						if(countDuty === 0) { //只有一个责任书的情况
							tt2Data[i].NAME = totalData.rowsDuty[j].NAME;
							countDuty++;
						} else {
							tt2Data[i].NAME += "," + totalData.rowsDuty[j].NAME;
							countDuty++;
						}
					}
				}
			}
			$("#tt2").datagrid("loadData", tt2Data); //载入数据
		}

		//停止合同
		function stopContract() {
			if(pageData.STATE === "到期") {
				$.messager.alert("警告", "该合同已经处于停用状态！");
				return;
			}
			if(pageData.STATE === "未开始" || pageData.STATE === "在租") {
				$.messager.alert("警告", "该合同仍然有摊位未停用！");
				return;
			}
			if(typeof(pageData) != "undefined") {
				for(var singleBoostData of pageData.rowsBoost) {
					if(singleBoostData.STATE === "在租") {
						$.messager.alert("警告", "该合同仍然有摊位未停用！无法停止合同！");
						return;
					}
					$.messager.confirm('Confirm', '确认停用该合同？', function(r) {
						if(r) {
							var row;
							confirmUrlAndData("stopContract", row, currid); //执行启用摊位操作
						}
					});
				}
			}
		}

		//启用摊位
		function startBoost() {
			var row = $("#tt").datagrid('getSelected');
			if(!row) {
				$.messager.alert("警告", "请选中需要启用的摊位!");
				return;
			}
			if(row.STATE === "在租") {
				$.messager.alert("警告", "该摊位已经处于启用状态！");
				return;
			}
			$.messager.confirm('Confirm', '确认启用该摊位？', function(r) {
				if(r) {
					confirmUrlAndData("startBoost", row, currid); //执行启用摊位操作
				}
			});
		}

		//停用摊位
		function stopBoost() {
			var row = $("#tt").datagrid('getSelected');
			if(!row) {
				$.messager.alert("警告", "请选中需要停用的摊位!");
				return;
			}
			if(row.STATE === "到期") {
				$.messager.alert("警告", "该摊位已经处于停用状态！");
				return;
			}
			$.messager.confirm('Confirm', '确认停用该摊位？', function(r) {
				if(r) {
					confirmUrlAndData("stopBoost", row, currid); //执行停用摊位操作
				}
			});
		}

		//退费操作
		function returnFee() {
			var row = $("#tt").datagrid('getSelected');
			if(!row) {
				$.messager.alert("警告", "请选中需要退费的摊位!");
				return;
			}
			$.messager.confirm("Confirm", "确认进行退费操作？", function(r) {
				if(r) {
					var data = new Object();
					data.ID = currid;
					localStorage.setItem("longTermContractData", JSON.stringify(data));
					var pLocation = "UI/Market/BIContract/BIContractReturnCharge.html?id=" + row.BOOST_ID;
					$("#ifrmEdit").attr("src", pLocation);
					constructDialog($("#dlg"), "新建长期合同收费管理", 1100, 410);
					AddDialog.dialog('open');
				}
			})
		}

		function getRefreshData() { //用于刷新摊位的状态
			$.ajax({
				dataType: 'JSON',
				url: RemoteLinkAddress + '/market/contract/findbyid.do?ID=' + currid,
				type: "GET",
				success: function(result) {
					console.log(result);
					$('#tt').datagrid('loadData', {
						total: 0,
						rows: []
					});
					$('#tt').datagrid('loadData', result.rowsBoost);
				},
				error: function(result) {
					$.messager.alert("错误信息", "保存失败");
				}
			});
		}

		function addIdentifierForChargeData(chargeData) {
			//给收费数据添加标志位，以此来区分新增数据与原有数据
			for(var data of chargeData) {
				data.isNewCharge = "false";
			}
			console.log(chargeData);
		}

		function getTotalCharge(totalData) {
			//得到总价
			var sum = parseFloat(totalData.RENT_SUM) + parseFloat(totalData.MARGIN_SUM) + parseFloat(totalData.OTHERS_SUM);
			for(var i = 0; i < totalData.rowsCharge.length; i++) {
				sum += parseFloat(totalData.rowsCharge[i].SUM);
			}
			return sum;
		}

		function refreshChargeData() {
			var chargeData = JSON.parse(localStorage.getItem("longTermCharge"));
			$("#tt1").datagrid("loadData", chargeData);
		}
	</script>

</html>